package com.edu.exam.entity.grading;

import com.edu.exam.enums.grading.ExpertiseLevel;
import com.edu.exam.enums.grading.OnlineStatus;
import com.edu.exam.enums.grading.ParticipantRole;
import com.edu.exam.enums.grading.ParticipantStatus;
import com.edu.exam.enums.grading.PermissionLevel;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.time.LocalDateTime;

/**
 * 协作参与者实体类
 * 所属模块：B-06 成绩管理模块
 *
 * 根据E-04-05 网上批阅子模块设计实现
 * 对应collaboration_participant数据表
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
public class CollaborationParticipant {

    @Id
    @Column(name = "participant_id", length = 64)
    private String participantId;

    /**
     * 会话ID
     */
    @Column(name = "session_id", nullable = false, length = 64)
    private String sessionId;

    /**
     * 教师ID
     */
    @Column(name = "teacher_id", nullable = false, length = 64)
    private String teacherId;

    /**
     * 角色：INITIATOR（发起人）、PARTICIPANT（参与者）、OBSERVER（观察者）、EXPERT（专家）、MODERATOR（主持人）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "role", nullable = false, length = 32)
    private ParticipantRole role;

    /**
     * 加入时间
     */
    @Column(name = "join_time", nullable = false)
    private LocalDateTime joinTime;

    /**
     * 离开时间
     */
    @Column(name = "leave_time")
    private LocalDateTime leaveTime;

    /**
     * 状态：ACTIVE（活跃）、INACTIVE（非活跃）、AWAY（离开）、BUSY（忙碌）、OFFLINE（离线）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 32)
    private ParticipantStatus status = ParticipantStatus.ACTIVE;

    /**
     * 贡献记录（JSON格式）
     */
    @Column(name = "contribution", length = 2000, columnDefinition = "TEXT")
    private String contribution;

    /**
     * 投票决策（JSON格式）
     */
    @Column(name = "vote_decision", length = 1000, columnDefinition = "TEXT")
    private String voteDecision;

    /**
     * 参与权重（0-1）
     */
    @Column(name = "participation_weight", precision = 3, scale = 2)
    private Double participationWeight;

    /**
     * 专家等级：NONE（无专家）、JUNIOR（初级）、SENIOR（高级）、EXPERT（专家）、MASTER（大师级）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "expertise_level", length = 16)
    private ExpertiseLevel expertiseLevel;

    /**
     * 专业领域
     */
    @Column(name = "specialization", length = 200)
    private String specialization;

    /**
     * 权限级别：READ_ONLY（只读）、COMMENT（评论）、EDIT（编辑）、MODERATE（管理）、FULL（完全权限）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "permission_level", length = 16)
    private PermissionLevel permissionLevel;

    /**
     * 最后活动时间
     */
    @Column(name = "last_activity_time")
    private LocalDateTime lastActivityTime;

    /**
     * 在线状态：ONLINE（在线）、OFFLINE（离线）、BUSY（忙碌）、AWAY（离开）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "online_status", length = 16)
    private OnlineStatus onlineStatus;

    /**
     * 连接设备信息
     */
    @Column(name = "device_info", length = 200)
    private String deviceInfo;

    /**
     * IP地址
     */
    @Column(name = "ip_address", length = 64)
    private String ipAddress;

    /**
     * 用户代理信息
     */
    @Column(name = "user_agent", length = 500)
    private String userAgent;

    /**
     * 时区
     */
    @Column(name = "timezone", length = 64)
    private String timezone;

    /**
     * 语言偏好
     */
    @Column(name = "language_preference", length = 16)
    private String languagePreference;

    /**
     * 参与时长（分钟）
     */
    @Column(name = "participation_duration_minutes")
    private Integer participationDurationMinutes;

    /**
     * 活跃时长（分钟）
     */
    @Column(name = "active_duration_minutes")
    private Integer activeDurationMinutes;

    /**
     * 发言次数
     */
    @Column(name = "speech_count")
    private Integer speechCount;

    /**
     * 评论次数
     */
    @Column(name = "comment_count")
    private Integer commentCount;

    /**
     * 投票次数
     */
    @Column(name = "vote_count")
    private Integer voteCount;

    /**
     * 提案次数
     */
    @Column(name = "proposal_count")
    private Integer proposalCount;

    /**
     * 质疑次数
     */
    @Column(name = "objection_count")
    private Integer objectionCount;

    /**
     * 支持次数
     */
    private Integer supportCount;

    /**
     * 反对次数
     */
    private Integer opposeCount;

    /**
     * 参与度评分（0-100）
     */
    @Column(name = "participation_score", precision = 5, scale = 2)
    private Double participationScore;

    /**
     * 协作质量评分（0-100）
     */
    @Column(name = "collaboration_quality_score", precision = 5, scale = 2)
    private Double collaborationQualityScore;

    /**
     * 贡献度评分（0-100）
     */
    @Column(name = "contribution_score", precision = 5, scale = 2)
    private Double contributionScore;

    /**
     * 满意度评分（1-5）
     */
    @Column(name = "satisfaction_score", precision = 3, scale = 2)
    private Double satisfactionScore;

    /**
     * 参与反馈（JSON格式）
     */
    @Column(name = "participation_feedback", length = 2000, columnDefinition = "TEXT")
    private String participationFeedback;

    /**
     * 个人笔记
     */
    @Column(name = "personal_notes", length = 2000, columnDefinition = "TEXT")
    private String personalNotes;

    /**
     * 标签（JSON格式）
     */
    @Column(name = "tags", length = 500)
    private String tags;

    /**
     * 是否被邀请
     */
    @Column(name = "is_invited")
    private Boolean isInvited;

    /**
     * 邀请人ID
     */
    @Column(name = "invited_by", length = 64)
    private String invitedBy;

    /**
     * 邀请时间
     */
    @Column(name = "invitation_time")
    private LocalDateTime invitationTime;

    /**
     * 是否接受邀请
     */
    @Column(name = "is_invitation_accepted")
    private Boolean isInvitationAccepted;

    /**
     * 邀请响应时间
     */
    @Column(name = "invitation_response_time")
    private LocalDateTime invitationResponseTime;

    /**
     * 拒绝原因
     */
    @Column(name = "rejection_reason", length = 500)
    private String rejectionReason;

    /**
     * 是否被移除
     */
    @Column(name = "is_removed")
    private Boolean isRemoved;

    /**
     * 移除人ID
     */
    @Column(name = "removed_by", length = 64)
    private String removedBy;

    /**
     * 移除时间
     */
    @Column(name = "removed_time")
    private LocalDateTime removedTime;

    /**
     * 移除原因
     */
    @Column(name = "removal_reason", length = 500)
    private String removalReason;

    /**
     * 扩展属性（JSON格式）
     */
    @Column(name = "additional_attributes", length = 2000, columnDefinition = "TEXT")
    private String additionalAttributes;

    /**
     * 创建时间
     */
    @Column(name = "created_time", nullable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 版本号（用于乐观锁）
     */
    @Version
    @Column(name = "version", nullable = false)
    private Integer version;

    // ================================
    // JPA 关联关系
    // ================================

    /**
     * 关联的协作会话
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "session_id", insertable = false, updatable = false)
    private CollaborationSession collaborationSession;

    }